package com.service.bank.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.client.model.pojo.bank.Record;
import com.client.model.pojo.bank.ArBankcard;
import com.client.model.pojo.bank.ArElectronic;
import com.client.model.pojo.bank.Record;
import com.client.model.pojo.user.ArUser;
import com.client.model.vo.deposit.RecordVo;
import com.service.bank.mapper.ArBankcardMapper;
import com.service.bank.mapper.ArElectronicMapper;
import com.service.bank.service.RecordService;
import com.service.bank.mapper.RecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
* @author liuwenju
* @description 针对表【record】的数据库操作Service实现
* @createDate 2024-04-01 20:55:27
*/
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record>
    implements RecordService{
    @Autowired
    private RecordMapper recordMapper;

    @Autowired
    private RedisTemplate<String ,String> redisTemplate;

    @Autowired
    private ArBankcardMapper arBankcardMapper;

    @Autowired
    private ArElectronicMapper arElectronicMapper;



    @Override
    public Page<Record> lists(String token, Integer offset, Integer pagesize) {
        Page<Record> page = new Page<>(offset, pagesize);
        String userInfo = redisTemplate.opsForValue().get("user:login" + token);
        ArUser sysUser = JSON.parseObject(userInfo, ArUser.class);
        Long uid = sysUser.getUid();
        System.out.println(uid);
        List<ArBankcard> arBankcards = this.arBankcardMapper.selectLists(uid);
        System.out.println("ssssss"+arBankcards);
        List<Record> recordList = new ArrayList<>();
        for (ArBankcard arBankcard : arBankcards){
           Page<Record>  records = this.recordMapper.selectLists(page, arBankcard.getBankCard());
            System.out.println("records"+recordList);
            recordList.addAll(records.getRecords());
        }
        System.out.println("recordList"+recordList);
        return page.setRecords(recordList);
    }

    @Override
    public Page<Record> listorders(String token, Integer offset, Integer pagesize) {
        Page<Record> page = new Page<>(offset, pagesize);
        String userInfo = redisTemplate.opsForValue().get("user:login" + token);
        ArUser sysUser = JSON.parseObject(userInfo, ArUser.class);
        Long uid = sysUser.getUid();
        System.out.println(uid);
        List<ArBankcard> arBankcards = this.arBankcardMapper.selectLists(uid);
        System.out.println("ssssss"+arBankcards);
        List<Record> recordLists = new ArrayList<>();
        for (ArBankcard arBankcard : arBankcards){
            Page<Record>  records = this.recordMapper.selectListsa(page, arBankcard.getBankCard());
            System.out.println("records"+recordLists);
            recordLists.addAll(records.getRecords());
        }
        return page.setRecords(recordLists);
    }

    @Override
    public Page<Record> chongorder(String token, Integer offset, Integer pagesize) {
        Page<Record> page = new Page<>(offset, pagesize);
        String userInfo = redisTemplate.opsForValue().get("user:login" + token);
        ArUser sysUser = JSON.parseObject(userInfo, ArUser.class);
        Long uid = sysUser.getUid();
        System.out.println(uid);
        List<ArElectronic> arElectronics = this.arElectronicMapper.selectLists(uid);
        System.out.println("qqqqqqqq"+arElectronics);
        List<Record> recordListss = new ArrayList<>();
        for (ArElectronic arElectronic : arElectronics){
            Page<Record> records = this.recordMapper.selectListsac(page,arElectronic.getCard());
            recordListss.addAll(records.getRecords());
            System.out.println("records"+recordListss);
        }
        return page.setRecords(recordListss);
    }

    @Override
    public Page<Record> tixianorder(String token, Integer offset, Integer pagesize) {
        Page<Record> page = new Page<>(offset, pagesize);
        String userInfo = redisTemplate.opsForValue().get("user:login" + token);
        ArUser sysUser = JSON.parseObject(userInfo, ArUser.class);
        Long uid = sysUser.getUid();
        System.out.println(uid);
        List<ArElectronic> arElectronics = this.arElectronicMapper.selectLists(uid);
        System.out.println("qqqqqqqq"+arElectronics);
        List<Record> recordListsss = new ArrayList<>();
        for (ArElectronic arElectronic : arElectronics){
            Page<Record> records = this.recordMapper.selectListsat(page,arElectronic.getCard());
            recordListsss.addAll(records.getRecords());
            System.out.println("records"+recordListsss);
        }
        return page.setRecords(recordListsss);
    }
}




